package com.hrzyit.base.widgets

import android.content.Context
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import com.hrzyit.base.R
import kotlinx.android.synthetic.main.layout_image_text_button.view.*

/**
 *
 * @author YangWei
 * @date 2019/3/23
 */
class ImageTextButton @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

    private var imageDrawable: Drawable? = null
    private var bottomText: String? = null

    init {

        // 初始化方法

        // 获取自定义属性 - layout_header_bar
        var typedArray = context.obtainStyledAttributes(attrs, R.styleable.ImageTextButton)


         imageDrawable = typedArray.getDrawable(R.styleable.ImageTextButton_imageDrawable)

        bottomText = typedArray.getString(R.styleable.ImageTextButton_bottomText)

        initView()

        // 释放属性资源
        typedArray.recycle()
    }

    private fun initView() {
        // 布局填充的的场景，使用前先实例化
        View.inflate(context, R.layout.layout_image_text_button, this)

        imageDrawable?.let {
            mTopIv.setImageDrawable(it)
        }

        bottomText?.let {
            mBottomTv.text = it
        }
    }

    fun getBottomView(): TextView {
        return mBottomTv
    }

    fun getBottomText(): String {
        return mBottomTv.text.toString()
    }
}